package com.chenjian.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenjian.entity.User;
import com.chenjian.mapper.UserMapper;
import com.chenjian.service.UserService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author chenjian
 * @since 2020-04-13
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {


    @Override
    public User getUser(Long id) {
        QueryWrapper<User> wrapper = Wrappers.query();
        wrapper.eq("id", id);
        List<User> users = this.baseMapper.getUsers(wrapper);
        if (null != users && users.size() == 1) {
            return users.get(0);
        }
        return null;
    }

    @Override
    public List<User> getByUserWithQueryUser(User queryUser) {
        QueryWrapper<User> wrapper = Wrappers.query();
        if (null != queryUser.getId()) {
            wrapper.lambda();
        }
        List<User> users = baseMapper.getUsers(wrapper);
        return users;
    }
}
